package de.hb.bv2.u04;


import ij.ImagePlus;
import ij.plugin.filter.PlugInFilter;
import ij.process.ImageProcessor;


/**
 * Diese Klasse ist fuer die GUI, um die GUI von der Logik zu trennen.
 * Uber die GUI kann auf die Logik zugegriffen werden. 
 */
public class Gruppe03_U04_GUI implements PlugInFilter
{

	/**
	 * 
	 * @see plugins.config
	 */
	private enum PluginFunctions 
	{
		NONE, 
		KONVEX,
		RCC
	};
  
	private PluginFunctions func = PluginFunctions.NONE;

  
	/**
	 * Method which is called when the filter is loaded
	 * 
	 * @param arg the argument given in plugins.config
	 * @param imp the currently active image
	 */
	public int setup(String arg, ImagePlus imp)
	{
		for(PluginFunctions inv : PluginFunctions.values())
		{
			if(inv.name().equals(arg)) 
			{
				func = inv;
				break;
			}
		}
		return DOES_8G;
	}

  
	/** 
   	 * Called once to process the image
   	 */
	public void run(ImageProcessor ip) 
	{
		long startTime = System.nanoTime();
  
		switch(func) 
		{
	    	case KONVEX:
	    		Gruppe03_U04_Logic.KonvexeHuelle(ip);
	    		break;
	    	case RCC:
	    		Gruppe03_U04_Logic.RCC_TopologischeRelationen(ip);
	    		break;
		}
    
		System.out.print(String.format("%s processing time: %.4fs\n", 
				func.name(), (System.nanoTime() - startTime) * 1e-9));
	}
  
}